﻿Pui.space = {
    init: function() {
        Pui.header.init();
        Pui.searching.init();
        Pui.msg.init('http://notice.pomoho.com/loadmessage.aspx?userid=' + _user.uid);
		if ('undefined' == typeof(json) || json) {
            if (_is_login) {
                this.islogin();
            } else {
                this.unlogin();
            }
        }
    },
	 unlogin: function() {
        var str = '';
        str += '<div class="row" id="topNav">';
        str += '<a title="登录" href="javascript:Pui.header.loginfo2(Pui.header.loginfo2_callback)">登录</a>';
        str += '<a title="注册" href="http://www.pomoho.com/ui/reg.aspx" target="_blank">注册</a>';
        if (document.location.host.toString().indexOf('home.pomoho.com') != -1) {
            str += '<a target="_blank" href="http://bbs.pomoho.com">论坛</a>';
        } else {
            str += '<a href="http://www.pomoho.com/upload/" target="_blank" title="论坛">论坛</a>';
        }
        str += '</div>';
        $("#top_Nav #L").html(str);
    },
	islogin: function() {
        var str = '';
        str += '<div class="row" id="topNav">';
        str += '<span class="s"><a class="count" title="你的帐户" href="http://www.pomoho.com/manage/index.aspx" target="_blank" >帐户</a>';
        str += '   <div class="dbd s3">';
        str += '     <ul>';
        str += '       <li><a class="d_item" title="我的视频" href="http://www.pomoho.com/manage/managevideo.aspx" target="_blank" >我的视频</a></li>';
        str += '       <li><a class="d_item" title="我的订阅" href="http://www.pomoho.com/manage/subscribevblog.aspx" target="_blank" >我的订阅</a></li>';
        str += '       <li><a class="d_item" title="我的收藏" href="http://www.pomoho.com/manage/managevideo.aspx?type=favs" target="_blank" >我的收藏</a></li>';
        str += '       <li><a class="d_item" title="我的相册" href="http://www.pomoho.com/manage/managealbum.aspx" target="_blank" >我的相册</a></li>';
        str += '     </ul>';
        str += '     <div class="m1"><a title="更多管理" href="http://www.pomoho.com/manage/index.aspx" target="_blank" >更多..&nbsp;&nbsp;</a></div>';
        str += '   </div>';
        str += ' </span>';
        if (document.location.host.toString().indexOf('home.pomoho.com') != -1) {
			str += ' <span class="s"><a class="msg" title="你的消息" href="http://www.pomoho.com/manage/messagelist.aspx?type=1" target="_blank" >消息</a><span>(0)</span>';
            str += '   <div class="dbd s2">';
            str += '     <div class="title"><div class="d_video">主题</div><div class="d_author">消息来源</div></div>';
            str += '     <ul>';
            str += '     </ul>';
            str += '     <div class="m"><a title="全部消息" href="http://www.pomoho.com/manage/messagelist.aspx?type=1" target="_blank" >全部消息&gt;&gt;</a></div>';
            str += '   </div>';
            str += ' </span>';
        } else {
			str += '<a target="_blank" href="http://bbs.pomoho.com">论坛</a>';  
        }
        str += ' <a title="退出登录" href="http://www.pomoho.com/ui/logout.aspx?AfterLoginReturnURL=' + window.location + '" >退出</a>';
        str += '</div>';
        $("#L").removeClass().html(str);
        this.SH();
        Pui.loadScript("http://notice.pomoho.com/loadmessage2.0.aspx?v=3");
    },
	SH: function() {
        var tim;
        $("#top_Nav #L .s").hover(function() {
            $(this).siblings().find(".dbd").hide();
            $(this).find(".dbd").show();
            clearTimeout(tim);
        },
        function() {
            tim = setTimeout(overDiv, 500);
            function overDiv() {
                $(this).find(".dbd").slideUp();
            }
        });
	},
    logInfo: function() {
        $('<div id="top_Nav"><div class="out" id="L"><ul><li class="s1 log"><a title="" href="javascript:Pui.header.loginfo2(Pui.header.loginfo2_callback);">登录</a></li><li class="s2 reg"><a href="http://www.pomoho.com/ui/reg.aspx" target="_blank">注册</a></li><li class="s2"><a target="_blank" href="http://bbs.pomoho.com">论坛</a></li></ul></div></div><script type="text/javascript">Pui.header.init();</script>').prependTo('#SpaceTitle');
    },
    emotion: function(what) {
        var emotionID = 1;
        $(what + ' .emotion').find('.l').click(function() {
            if (emotionID >= 2) {
                $('#emotionBox').animate({
                    left: -(450 * (emotionID - 2))
                },
                1000);
                if (emotionID == 2) {
                    $(what + ' .l').removeClass('l_b').attr('title', '左边没有了');
                } else if (emotionID == 4) {
                    $(what + ' .r').addClass('r_b').attr('title', '向右翻');
                }
                emotionID--;
            }
            this.blur();
            return false;
        }).end().find('.r').click(function() {
            if (emotionID <= 3) {
                $('#emotionBox').animate({
                    left: -(450 * emotionID)
                },
                1000);
                if (emotionID == 1) {
                    $(what + ' .l').addClass('l_b').attr('title', '向左翻');
                } else if (emotionID == 3) {
                    $(what + ' .r').removeClass('r_b').attr('title', '右边没有了');
                }
                emotionID++;
            }
            this.blur();
            return false;
        }).end().find('div a').each(function() {
            $(this).click(function() {
                var tmp = $(what + ' textarea').val() + $(this).find('img').attr('src').replace(/.+\/(em\d+)\.gif/g, '[$1]');
                $(what + ' textarea').val(tmp);
                return false;
            });
        });
    },
    emotionWR: function(what) {
        var s = '';
        s += '<div style="position:relative;width:450px;height:60px;overflow:hidden;margin:5px auto;"><div id="emotionBox" style="position:absolute;left:0;top:0;width:1800px;">';
        var l = 'http://static.pomoho.com/images/em/';
        var alt = ['黑星打', '大', '泡', '蹦', '继续', '狂', '黑星殴', '吹', '捅', '被殴', '飞', '嘘', '赖', '顶', '变', '滚球', '生', '膜拜', '转', '口', 'KI', '鬼', '抓狂', '扯', '流', '闭嘴', 'HI', '可爱', '摇', '躲', '多', '吉'];
        for (var i = 1; i <= 4; i++) {
            s += '<div style="width:450px;float:left;text-align:center;">';
            for (var j = (i - 1) * 8 + 1; j <= i * 8; j++) {
                if (j <= 32) {
                    s += '<a href="" title="' + alt[j - 1] + '" style="margin:0 1px;"><img src="' + l + 'em' + j + '.gif" height="50" width="50" /></a>';
                }
            }
            s += '</div>';
        }
        s += '</div></div>';
        s += '<a href="" class="l" title="左边没有了">向左翻</a><a href="" class="r r_b" title="向右翻">向右翻</a>';
        $(s).appendTo($('.emotion'));
        this.emotion(what);
        this.commentLoad();
    },
    commentLoad: function() {
        Pui.ajaxLoad('GET', 'http://home.pomoho.com/do/interfaces/getvideoreview.aspx', 'videoid=' + flvid + '&r=' + Math.random(), 'html', '#Comment .loading',
			function() {
				$('.commentAdd').before(_getDATA);
			});
    },
    commentReply: function(what) {
        this.SetValidCodeImg(what);
        var _self = this;
        $('#post_content').bind('focus',
        function() {
            _self.CodeImgLoader()
        });
        $(what + ' input[@type=submit]').click(function() {
            textarea = $(what + ' textarea');
            if ($.trim(textarea.val()) == '') {
                alert('留言内容不可为空！');
                textarea.focus();
                return;
            }
            var sValidCode = "";
            if (document.getElementById("tb_validcode") != null) {
                sValidCode = document.getElementById("tb_validcode").value;
                if ($.trim(sValidCode) == '') {
                    alert('验证码不可为空！');
                    return;
                }
            }
            var content = textarea.val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->");
            if (_is_login) {
                switch (what) {
                case '#Comment':
                    Pui.loadScript(baseurl + "/video/dealajaxdata.aspx?itype=1&imdbid=" + flvid + "&content=" + content + "&validcode=" + sValidCode, {
                        random: true
                    });
                    break;
                case '#GuestBook':
                    Pui.loadScript(baseurl + "/space/personjs.aspx?dotype=4&userid=" + _space_user.uid + "&content=" + escape(content) + "&validcode=" + sValidCode, {
                        random: true
                    });
                }
                var ct = Pui.ui.pos.elementTop(document.getElementById(what.slice(1)));
                window.scrollTo(0, ct - 30);
                this.blur();
                setTimeout("Pui.space.commentReplyFill()", 1000);
                _self.GetValidCodeImg();
                return false;
            } else {
                flag = 6;
                Pui.header.loginfo();
            }
        });
    },
    commentJudge: function() {
        var sValidCode = document.getElementById("tb_validcode").value;
        if (document.getElementById('Comment')) {
            var content = $('#Comment textarea').val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->");
            Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=1&imdbid=" + flvid + "&content=" + escape(content) + "&validcode=" + sValidCode, {
                random: true
            });
        } else if (document.getElementById('GuestBook')) {
            var content = $('#GuestBook textarea').val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->");
            Pui.loadScript(baseurl + "/space/personjs.aspx?dotype=4&userid=" + _space_user.uid + "&content=" + escape(content) + "&validcode=" + sValidCode, {
                random: true
            })
        }
        setTimeout("Pui.space.commentReplyFill()", 1000);
        Pui.space.GetValidCodeImg();
        Pui.header.closeDiv();
    },
    hideComment: function(num) {
        if (String(window.location).match(/http:\/\/home.*/)) {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        } else {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        }
        $('#Comment h3 span.count').html(20);
    },
    commentQuote: function(bid) {
        var re_q_txt = document.getElementById("re_q_" + bid).value;
        document.getElementById("post_content").value = "[quote]" + re_q_txt + "[/quote]";
        $('#Comment textarea').focus();
    },
    commentReplyFill: function() {
        var c = textarea.val().replace(/\[em(\d+)\]/g, "<img src='http://static.pomoho.com/images/em/em$1.gif' />");
        var u = _is_login ? '<a href="javascript:;">' + _user.nick + '</a>': '游客';
        var s = '';
        var mdL = $('#Comment .cl').length;
        var icount = $('#CM h3 .title span').text() ? $('#CM h3 .title span').text() : 0;
        icount = parseInt(icount);
        var vtitle = $.trim($('title').html());
        var s_href = 'http://video.pomoho.com/review.aspx?flvid=' + flvid + '&icount=' + (icount + 1) + '&title=' + vtitle + '&uid=' + _space_user.uid;
        if (mdL) {
            s += '<div class="mDocument" style="_width:100%;">';
            s += ' <div class="photo"><img src="http://static.pomoho.com/static/images/photo_68.gif" alt="" /></div>';
            s += ' <div class="detail">';
            s += '  <span class="n_user">' + u + '</span>';
            s += '  <p class="text">' + c + '</p>';
            s += ' </div>';
            s += ' <div class="handle">';
            s += '  <span class="t_release">' + Pui.ui.gettime() + '</span>';
            s += ' </div>';
            s += '</div>';
            $('#Comment .cl').prepend(s).fadeTo('slow', 1);
            $('#CM h3 .title span').text(icount + 1).parents('h3').find('.more a').attr('href', s_href);
        } else {
            s += '<h3><span class="title">网友评论（共<span>' + (icount + 1) + '</span>条）</span><span class="more"><a target="_blank" href="' + s_href + '">更多</a></span></h3>';
            s += '<div class="cl showblock"><div class="mDocument">';
            s += ' <div class="photo"><img src="http://static.pomoho.com/static/images/photo_68.gif" alt="" /></div>';
            s += ' <div class="detail">';
            s += '  <span class="n_user">' + u + '</span>';
            s += '  <p class="text">' + c + '</p>';
            s += ' </div>';
            s += ' <div class="handle">';
            s += '  <span class="t_release">' + Pui.ui.gettime() + '</span>';
            s += ' </div>';
            s += '</div></div>';
            $('#span_video_review').prepend(s).fadeTo('slow', 1);
        }
        textarea.attr('value', '').focus();
    },
    doingReply: function() {
        var timer_doing = null;
        $('#Doing input[@type=submit]').click(function() {
            var content = $.trim($('#Doing textarea').val());
            if (content == null) {
                alert('记事内容不可为空！');
                $('#Doing textarea').focus();
                return;
            }
            if (timer_doing != null) {
                var d = new Date();
                if ((Date.parse(d.toUTCString()) - 60000) < timer_doing) {
                    alert('留言间隔不得少于1分钟！');
                    $('#Doing textarea').focus();
                    return;
                }
            } else {
                var d = new Date();
                timer_doing = Date.parse(d.toUTCString());
            }
            var ct = Pui.pos.elementTop($('#Doing')[0]);
            window.scrollTo(0, ct - 30);
            this.blur();
            setTimeout("Pui.space.doingReplyFill()", 1000);
            var content = escape(content.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace('\'', '‘'));
            Pui.loadScript(baseurl + "/space/mydoingajax.aspx?opreatetype=add&writecontent=" + content + "&userid=" + _space_user.uid, {
                random: false
            });
            return false;
        });
    },
    doingReplyFill: function() {
        var c = $.trim($('#Doing textarea').val());
        var s = '<li><div>' + c + '</div><p>书写于<span>现在</span><a href="javascript:;" onclick="$(this).parent().parent().hide()" class="is_login" title="删除">删</a></p></li>';
        if (!$('#Doing .nl')[0]) {
            $('#Doing h2').after('<div class="nl detail"></div>');
        }
        $(s).prependTo('#Doing .nl');
        $('#Doing textarea').attr('value', '').focus();
    },
    GetValidCodeImg: function() {
        ValidCodeURL = baseurl + "/video/ValidCode.aspx?type=1";
        document.getElementById('Comment') ? document.getElementById("validcode").src = ValidCodeURL + "&objid=" + flvid + "&ran=" + Math.random() : document.getElementById("validcode").src = ValidCodeURL + "&objid=" + _space_user.uid + "&ran=" + Math.random();
    },
    CodeImgLoader: function() {
        var s = '<a href="javascript:Pui.space.GetValidCodeImg();" title="看不清楚？请点击刷新验证码！" style="position:relative;top:-3px;*top:-2px;" ><img id="validcode" border=0  width="60" height="20" src="" /></a>';
        $('#tb_validcode').after(s).removeAttr('onfocus');
        $('#post_content').unbind('focus');
        $('#post_content').click(function() {
            if ($("#QuickComment").length > 0) {
                $(".f_v").hide();
                $("#QuickComment").hide();
            }
        });
		this.GetValidCodeImg();
    },
    SetValidCodeImg: function(what) {
        var ValidCodeHtml = '';
        ValidCodeHtml = '请输入验证码&nbsp;&nbsp;<input id="tb_validcode" type="text" onfocus="javascript:Pui.space.CodeImgLoader();" style="width:60px; border:1px #7B9EBD solid;margin:0 5px 0 0;" />';
        var s = $(what + ' .commentAdd .form .submit').html();
        $(what + ' .commentAdd .form .submit').html(ValidCodeHtml + s);
    },
    SendCallBack: function(v, sv) {
        if (v == 0) {
            alert("您的验证码错误！");
        }
        if (v == -1) {
            alert("您的验证码已失效。请点击验证码图片，重新获取验证码！");
        }
        setTimeout("$('#Comment .mDocument').eq(0).remove();", 1000);
        if ($('#Comment .cl').length > 1) {
            $('#Comment .cl').eq(0).remove();
            $('#Comment h3').eq(0).remove();
        }
        setTimeout("textarea.attr('value', '" + sv + "').focus();", 1000);
        setTimeout(function() {
            var icount = $('#CM h3 .title span').text() ? $('#CM h3 .title span').text() : 0;
            icount = parseInt(icount);
            var vtitle = $.trim($('title').html());
            var s_href = 'http://video.pomoho.com/review.aspx?flvid=' + flvid + '&icount=' + (icount - 1) + '&title=' + vtitle + '&uid=' + _space_user.uid;
            $('#Comment h3 .title span').text(icount - 1).parents('h3').find('.more a').attr('href', s_href);
        },
        1500);
    },
	conceal:function(){
		var page=$('.Popular .page li')
		page.click( function () {
			var page=$(this);
			if(page.parent().children().length<=1)return false;
			page.addClass('ac').siblings().removeClass('ac');
			var mm=page.parent().children().index(page[0]);
			page.parents('.Popular').find('.cover').css('display','none').eq(mm).css('display','block');
			return false;
		});
	}
}
/*播放页热门视频*/
function focusTurn(){
	var i=0,yc=$('.Popular .cover'),l=yc.length,s='';
	function num(){
		yc.parent().find('.page li').removeClass('ac').click(function(){
			clearTimeout(t);
			var _self=$(this);
			_self.addClass('ac');
			i=_self.text()-1;
			g();
			return false;											 
		});
	}
	function g(){
		yc.css('display','none').parent().find('.page li').removeClass('ac');
		if(i<l){
			yc.eq(i).css('display','block').parent().find('.page li:eq('+i+')').addClass('ac');
			i++;
			t=setTimeout(function(){g()},3000);
		}
		else{i=0;g();}
	}
	if(l){num();g();}
}
Pui.video = {
    init:function()
    {
        Pui.video.hotVideo();
        Pui.video.userVideoList();
    },
    quote: function(bid) {
        Pui.space.commentQuote.call(this, bid);
    },
    collect: function() {
        Pui.space.video.collect.call(this);
    },
    hotVideo:function()
    {
        $.getJSON("http://video.pomoho.com/do/interfaces/getchannelhotvideo.aspx?jsoncallback=?", {num: 19, cid: typeof(channelId) != 'undefined' ? channelId : -1}, function(json)
        {
            if(json!=null&&json.length>0)
            {
                var jsonlen=json.length;
                if(jsonlen>9)
                {
                    hotVideoPlay(json.slice(0,9));
                    hotVideoSearch(json.slice(9));
                }
                else
                {
                    hotVideoSearch(json);
                }
            }
        });
        var hotVideoSearch=function(arrJson)
        {
            $("<div>")
                    .attr({id:"div_recommend"})
                    .insertAfter($("#div_relatedSearch"));
                
                var strLiList='';
				for(var i=0;i<arrJson.length;i++)
				{
					strLiList+="<li>";
					strLiList+="<a href=\"http://search.pomoho.com/videosearch.aspx?_keyword="+encodeURIComponent(arrJson[i].videoName)+"&_f=P0S04&vid="+arrJson[i].videoID+"\" title=\""+arrJson[i].videoName+"\" target=\"_blank\"><img alt=\""+arrJson[i].videoName+"\" src=\""+arrJson[i].imgURL+"\"></a>";
					strLiList+="<p><a href=\"http://search.pomoho.com/videosearch.aspx?_keyword="+encodeURIComponent(arrJson[i].videoName)+"&_f=P0S04&vid="+arrJson[i].videoID+"\" title=\""+arrJson[i].videoName+"\" target=\"_blank\">"+arrJson[i].videoName+"</a></p>";
					strLiList+="</li>";
				}
				var recommendBox="<div class=\"videolist Recommend\">";
                    recommendBox+="<div class=\"bt_title\"><h2>推荐视频</h2></div>";
                    recommendBox+="<div class=\"showblock\">";
                        recommendBox+="<ul>";
                        recommendBox+=strLiList;
                        recommendBox+="</ul>";
                    recommendBox+="</div>";
				recommendBox+="</div>";
                $("#div_recommend").html(recommendBox);
        };
        var hotVideoPlay=function(arrJson)
        {
			var strList="<div class=\"Popular\" style=\"display:none\">";
			strList+="<div class=\"bt_title\"><a target=\"_blank\" href=\"http://www.pomoho.com/"+arrJson[0].channelText+"/"+arrJson[0].channelText+",video,week,1\">更多</a><h2>热门视频</h2></div>";
			strList+="<div class=\"showblock\">";

			var strPage ='';
			var iPage = 1;
			for (var i = 0; i < arrJson.length; i ++)
			{
				if (i % 3 == 0)
				{
					strList+="<ul class=\""+(i == 0 ? "cover" : "hide cover")+"\">";
				}
				
				strList+="<li>";
				strList+="<a href=\""+arrJson[i].spaceURL+"/"+arrJson[i].videoID+"?P0P08\" title=\""+arrJson[i].videoName+"\" target=\"_blank\"><img alt=\""+arrJson[i].videoName+"\" src=\""+arrJson[i].imgURL+"\"></a>";
				strList+="<p><a href=\""+arrJson[i].spaceURL+"/"+arrJson[i].videoID+"?P0P08\" title=\""+arrJson[i].videoName+"\" target=\"_blank\">"+arrJson[i].videoName+"</a></p>";
				strList+="</li>";
					
				if ((i + 1) % 3 == 0 || i == arrJson.length - 1)
				{
					strList+="</ul>";
					strPage+="<li "+(strPage==''?"class=\"ac\"" : "")+">"+(iPage ++)+"</li>";
				}
			}
			strList+="<div class=\"page\">";
			strList+="<ol>"+strPage+"</ol>";
			strList+="</div>";
			strList+="</div>";
			strList+="</div>";
			if($("#ByRight .Popular").length>0)
			{
			    $("#ByRight .Popular").remove();
			}
			$("#ByRight").prepend(strList);
            $("#ByRight .Popular").slideDown(2500);
            focusTurn();
        };
    },
    userVideoList:function()
    {
        var arrVideo =
        [
        "白俄罗斯美女是国宝 禁止出国|http://static.pomoho.com/pics/1_1_3535902261910.jpg|%e7%99%bd%e4%bf%84%e7%bd%97%e6%96%af%e7%be%8e%e5%a5%b3%e6%98%af%e5%9b%bd%e5%ae%9d+%e7%a6%81%e6%ad%a2%e5%87%ba%e5%9b%bd",
        "日和漫画全集|http://static.pomoho.com/pics/1_1_3544743824410.jpeg|%e6%97%a5%e5%92%8c%e6%bc%ab%e7%94%bb",
        "美女恶搞好色男顾客|http://static.pomoho.com/pics/1_1_3544485699410.jpeg|%e7%be%8e%e5%a5%b3%e6%81%b6%e6%90%9e%e5%a5%bd%e8%89%b2%e7%94%b7%e9%a1%be%e5%ae%a2",
        "九尾狐姐姐传|http://static.pomoho.com/pics/1_1_3543980699410.jpg|%e4%b9%9d%e5%b0%be%e7%8b%90%e5%a7%90%e5%a7%90%e4%bc%a0",
		"迎娶性感新娘的悲惨下场|http://static.pomoho.com/pics/1_1_3545650699410.jpg|%E8%BF%8E%E5%A8%B6%E6%80%A7%E6%84%9F%20%E6%96%B0%E5%A8%98%20%E6%82%B2%E6%83%A8%E4%B8%8B%E5%9C%BA", 
		"恶搞银行收费：抢你没商量|http://static.pomoho.com/pics/1_1_3543496011910.jpg|%E6%8A%A2%E4%BD%A0%E6%B2%A1%E5%95%86%E9%87%8F", 
		"爆笑：诡异的连环伤亡事件|http://static.pomoho.com/pics/1_1_3536466324410.jpeg|%E8%AF%A1%E5%BC%82%E7%9A%84%E8%BF%9E%E7%8E%AF%E4%BC%A4%E4%BA%A1%E4%BA%8B%E4%BB%B6", 
		"恶搞：挡不住的地铁诱惑|http://static.pomoho.com/pics/1_1_3538551011910.jpeg|%e6%81%b6%e6%90%9e%ef%bc%9a%e6%8c%a1%e4%b8%8d%e4%bd%8f%e7%9a%84%e5%9c%b0%e9%93%81%e8%af%b1%e6%83%91", 
		"马诺成名前写真岁少女终极诱惑|http://static.pomoho.com/pics/1_1_3544254918160.jpeg|%E9%A9%AC%E8%AF%BA%E6%88%90%E5%90%8D%E5%89%8D%E5%86%99%E7%9C%9F"
        ];
        var struserVideoList="<div class=\"videolist\" id=\"Trundle\">";
            	//struserVideoList+="<div class=\"bt_title\"><h2>该播客的视频列表</h2></div>";
                struserVideoList+="<div class=\"showblock\">";
                struserVideoList+="<div class=\"demo\">";
                var videoname = "";
                var videoimg = "";
                var enname  = "";
                var arrtemp=[];
                var num=0;
                var displayNum = Math.ceil(Math.random() * 3);
                for (var i = 0; i< 3; i++) {
					if (i != (displayNum - 1)) {
						num+= 3;
						continue;
					}
                    struserVideoList+="<ul class=\"row\">";
                    for (var j = 0; j <= 2; j++) {
                        arrtemp=arrVideo[num++].split('|');
                        if(arrtemp.length<3) {
                            return ;
                        }
                        videoname=arrtemp[0];
                        videoimg=arrtemp[1];
                        enname = arrtemp[2];
                        struserVideoList+="<li>";
                        struserVideoList+="<a href=\"http://search.pomoho.com/videosearch.aspx?_keyword="+enname+"&_f=P0S06\" title=\""+videoname+"\" target=\"_blank\"><img alt=\""+videoname+"\" src=\""+videoimg+"\"></a>";
                        struserVideoList+="<p><a href=\"http://search.pomoho.com/videosearch.aspx?_keyword="+enname+"&_f=P0S06\" title=\""+videoname+"\" target=\"_blank\">"+videoname+"</a></p>";
                        struserVideoList+="</li>";
                    }
                    struserVideoList+="</ul>";
                    }
                struserVideoList+="</div>";
            struserVideoList+="</div>";
        $("#Bar .videolist").eq(0).before(struserVideoList);
    }
}
Pui.space.video = {
    init: function() {
        Pui.space.init();
        Pui.loadScript('http://live.pomoho.com/getxmldata.aspx?type=2&ids=' + flvid + '_999');
        Pui.space.emotionWR('#Comment');
        Pui.space.commentReply('#Comment');
        Pui.space.hideComment(5);
        Pui.autoThumb('.albumlist li img', 78, 58);
		if(document.getElementById('Space_NewVideo')){
			this.gotoLink();
		} ;
		Pui.video.init();
    },
    share: function(link, title, content) {
        var itieba_share = 'http://tieba.baidu.com/i/sys/share?link=' + link + '&type=video&title=' + title + '&content=' + content;
        if (!window.open(itieba_share, 'itieba', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=626,height=436')) {
            location.href = itieba_share;
        }
    },
    collect: function() {
        Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=2&imdbid=" + flvid);
    },
    gotoLink: function() {
        var vTitle = encodeURIComponent($('title').html().replace(/(^\s*)|(\s*$)/g, ""));
        var vLink = encodeURIComponent('http://home.pomoho.com/' + _space_user.username + '/' + flvid);
        var vContent = encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid);
        var vSource = encodeURIComponent('爆米花网');
        var vSourceUrl = encodeURIComponent('http://www.pomoho.com/');	
        var s = '<span class="icos"><a id="renren" href="http://share.renren.com/share/buttonshare.do?link=' + vLink + '&title=' + vTitle + '" target="_blank" title="转贴至人人网">转贴至人人网</a><a id="kaixin" href="http://www.kaixin001.com/repaste/share.php?rurl=' + vLink + '&rcontent=' + vLink + '&rtitle=' + vTitle + '" target="_blank" title="转贴至开心网">转贴至开心网</a><a id="sina" href="http://v.t.sina.com.cn/share/share.php?c=spr_web_bd_pomoho_weibo&url=' + vLink + '&title=' + vTitle + '&source=' + vSource + '&sourceUrl=' + vSourceUrl + '" target="_blank" title="转贴至新浪微博">转贴至新浪微博</a><a id="itieba" href="" onclick="Pui.space.video.share(\'' + vLink + '\',\'' + vTitle + '\',\'' + vContent + '\');return false;" title="转贴至i贴吧">转贴至i贴吧</a></span>';
        $(s).appendTo('.video_info .handle');
        this.zz();
    },
    zz: function(mv) {
        var urlParm = "";
        var htmlcode = '';
        var vTitle = encodeURIComponent($('title').html().replace(/(^\s*)|(\s*$)/g, ""));
        var vLink = encodeURIComponent('http://home.pomoho.com/' + _space_user.username + '/' + flvid);
        var vContent = encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid);
        var vSource = encodeURIComponent('爆米花网');
        var vSourceUrl = encodeURIComponent('http://www.pomoho.com/');
        var s = '';
        s += '<div id="ZZ" style="display:none;">';
        s += ' <div class="s1">';
        urlParm = "flvid";
        htmlcode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="396" id="object"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid + '" /><embed src="http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid + '" quality="high" width="480" height="396" allowScriptAccess="always"/></object>';
        if (String(window.location).match(/http:\/\/video\.dvod.*/)) {
            s += '  此节目地址（URL）<br /><input type="text" class="url" value="http://video.dvod.com.cn/news/' + flvid + '.shtml" /><br />';
        } else {
            s += '  此节目地址（URL）<br /><input type="text" class="url" value="http://home.pomoho.com/' + _space_user.username + '/' + flvid + '" /><br />';
        }
        s += '  把播放器显示到个人空间或Blog<br /><input type="text" class="url" value="http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid + '" /><br />';
        s += '  HTML代码,适用于个人空间（或其他类型的Blog）<br /><input type="text" class="url" value="" /><br />';
        s += '  BBS代码<br /><input type="text" class="url" value="[flash]http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid + '[/flash]" />';
        s += ' </div>';
        s += '  <p><a href="" onclick="$(\'#ZZ\').slideUp();return false;">关闭</a></p>';
        s += '</div>';
        var vPath = '#VideoPlayer .handle';
        $(s).appendTo($('#Space')).css({
            'z-index': '9999',
            'top': '402px',
            'left': '16px'
        });
        $(vPath).find('.s4').click(function() {
            $('#ZZ').slideToggle('slow');
            this.blur();
            return false;
        });
        $('#ZZ .url').eq(2).attr('value', htmlcode).end().hover(function() {
            $(this).select();
        },
        function() {
            $(this).blur();
        });
    },
    hideComment: function(num) {
        if (String(window.location).match(/http:\/\/home.*/)) {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        } else {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        }
        $('#Comment h3 span.count').html(20);
    }
}
Pui.space.guestbook = {
    init: function() {
        Pui.space.init();
        Pui.space.emotionWR('#GuestBook');
        Pui.space.commentReply('#GuestBook');
    }
}